package com.zjsru.plan2024.oneday;

import java.util.Arrays;
import java.util.List;

/**
 * 3248. 矩阵中的蛇
 *
 * @Author: cookLee
 * @Date: 2024-11-21
 */
public class FinalPositionOfSnake {

    /**
     * 主
     * \
     * 输入：n = 2, commands = ["RIGHT","DOWN"]
     * <p>
     * 输出：3
     * \
     * 输入：n = 3, commands = ["DOWN","RIGHT","UP"]
     * <p>
     * 输出：1
     * \
     *
     * @param args args
     */
    public static void main(String[] args) {
        FinalPositionOfSnake finalPositionOfSnake = new FinalPositionOfSnake();
        int n = 2;
        List<String> commands = Arrays.asList("RIGHT", "DOWN");
        System.out.println(finalPositionOfSnake.finalPositionOfSnake(n, commands));
    }

    /**
     * 模拟
     *
     * @param n        n
     * @param commands 命令
     * @return int
     */
    public int finalPositionOfSnake(int n, List<String> commands) {
        int ans = 0;
        for (String command : commands) {
            if (command.equals("RIGHT")) {
                ans++;
            } else if (command.equals("LEFT")) {
                ans--;
            } else if (command.equals("UP")) {
                ans -= n;
            } else {
                ans += n;
            }
        }
        return ans;
    }

}
